<?php

/**
 * 
 * @author coelho
 */
class SubDownloaderCli {
	
	/**
	 * Language of subtitles (Eg: eng, pob, por)
	 * 
	 * default: eng
	 * @var string 
	 */
	var $language = "eng";
	
	/**
	 * Full path to your video(s). Don't use '~'
	 * @var string array
	 */
	var $path_to_scan;
	
	/**
	 * Set true to Rename subtitles to match movie file name
	 * @var boolean
	 */
	var $rename_subs = false;
	
	/**
	 * Path to subdownloader cli on server
	 * @var string
	 */
	var $exec_path = "/usr/bin/subdownloader";
	
	public function __construct($exec_path) {
		$this->exec_path = $exec_path;
	}
	
	/**
	 * Execute command
	 */
	public function exec() {
		$ret = array();
		
		exec($this->build_cmd(),$ret);
		return $ret;
	}
	
	/**
	 * Build command line 
	 */
	public function build_cmd() {
		$rename_cmd = $this->rename_subs ? " --rename-subs " : "";
		
		$cmd = sprintf("%s -c -q --lang=%s %s -V '%s'",$this->exec_path,$this->language,$rename_cmd,$this->path_to_scan);
		
		return escapeshellcmd($cmd);
	}
	
	
	
}